﻿@model Model.AppUserList
@{
    ViewBag.Title = "DCJDOrderInfo";
    Layout = "~/Views/Shared/_JQBaseLayOut.cshtml";
}
@using Model

@section JQscriptSection{
    <script type="text/javascript" src="../../Scripts/LodopFuncs.js"></script>
    <script type="text/javascript" src="../../Scripts/PrintModelJD.js"></script>
    <script type="text/javascript" src="http://localhost:8000/CLodopfuncs.js?priority=1"></script>
    <object id="LODOP_OB" classid="clsid:2105C259-1E0C-4534-8141-A753534CB4CA" width="0" height="0">
        <embed id="LODOP_EM" type="application/x-print-lodop" width="0" height="0" /></object>
    <script src="../../Scripts/jqueryeasyui/datagrid-detailview.js" type="text/javascript"></script>
    <script type="text/javascript">
        var LODOP = getLodop(document.getElementById('LODOP_OB'), document.getElementById('LODOP_EM'));
        $(document).ready(function () {
            var curr_time = new Date();
            var strDate = curr_time.getFullYear() + "-";
            strDate += curr_time.getMonth() + 1 + "-";
            strDate += curr_time.getDate();
            $("#checkTimeS").datebox("setValue", strDate);
            $("#checkTimeE").datebox("setValue", strDate);
            InitGrid();
        });

        HandleDom.ClassTriggerClick("icon-reload", function () {
            InitGrid();
        });

        HandleDom.ClassTriggerClick("icon-thirddis", function () {
            var row = HandleData.GetDataGridSelected("dg");
            HandleData.ClearForm('location');
            HandleDialog.OpenDialog(row, 'p2', '订单配送分配', function () {
                $('#selectDis').combobox('setValue', '1');

            });
        });
        HandleDom.ClassTriggerClick("icon-preview", function () {
            Preview();
        });
        HandleDom.ClassTriggerClick("icon-printer", function () {
            Print();
        });
        HandleDom.ClassTriggerClick("icon-ok", function () {
            deliveryEndOrder();
        });

        function InitGrid() {
            var OrderCode = $('#txtOrderCode').val();
            var startDate = $('#checkTimeS').datebox('getValue');
            var endDate = $('#checkTimeE').datebox('getValue');
            var Status = $('#status').combobox('getValue');
            var disGs = $('#disGs').combobox('getValue');
            var disStatus = $('#disStatus').combobox('getValue');

            queryParams = {
                OrderCode: OrderCode,
                checkTimeS: startDate,
                checkTimeE: endDate,
                Status: Status,
                disGs: disGs,
                disStatus: disStatus
            }
            HandleData.InitDataGrid('dg', '/DCJDOrderInfo/InitJsonResult', 'toolbar', queryParams, 'ORDERID', true, function (data) { },
                function (rowIndex, rowData) {//双击
                    //edit(rowData);
                });


            $('#dg').datagrid({
                view: detailview,
                detailFormatter: function (index, row) {
                    return '<div style="padding:2px"><table class="ddv"></table></div>';
                },
                onExpandRow: function (index, row) {
                    $('#dg').datagrid("loading", "正在检索数据...");
                    var ddv = $(this).datagrid('getRowDetail', index).find('table.ddv');
                    ddv.datagrid({
                        url: '/DCJDOrderInfo/QueryDetailData' + '?ORDERCODE=' + row.ORDERCODE,
                        fitColumns: true,
                        singleSelect: true,
                        rownumbers: true,
                        loadMsg: '',
                        height: 'auto',
                        columns: [[
                            { field: 'ORDERDETAILID', title: '订单明细ID', align: 'center', sortable: true, hidden: true },
                            { field: 'ORDERID', title: '订单ID', align: 'center', sortable: true, hidden: true },
                            { field: 'ORDERCODE', title: '订单号', align: 'center', sortable: true },
                            { field: 'GOODSCODE', title: '商品编码', align: 'center', sortable: true },
                            { field: 'GOODSNAME', title: '商品名称', align: 'center', sortable: true },
                            { field: 'GOODSNUMBER', title: '商品数量', align: 'center', sortable: true },
                            { field: 'PRICE', title: '商品单价', align: 'center', sortable: true }
                        ]],
                        onResize: function () {
                            $('#dg').datagrid('fixDetailRowHeight', index);
                        },
                        onLoadSuccess: function () {
                            $('#dg').datagrid("loaded");
                            setTimeout(function () {
                                ddv.datagrid('fixDetailRowHeight', index);
                            }, 0);
                        },
                        loadFilter: function (data) {
                            if (data.ResponseData) {
                                return data.ResponseData;
                            } else {
                                return data;
                            }
                        }
                    });
                    $('#dg').datagrid('fixDetailRowHeight', index);
                }
            });

        }

        function saveThirdDis() {
            var orderID = "";
            var orderIDError = "";
            var rows = $('#dg').datagrid('getSelections');
            for (var i = 0; i < rows.length; i++) {
                if (rows[i].STATUS == '0') {
                    orderID = orderID + rows[i].ORDERID + ",";
                } else {
                    orderIDError = orderIDError + rows[i].ORDERID + ",";
                }

            }
            $('#hiddenOrderID').val(orderID);
            if (orderIDError != "") {
                layer.alert(orderIDError + "已下架不能推送！", 3);
            } else {
                HandleRequest.submitForm('location_Dis', '@Url.Action("SaveDataDis", "DCJDOrderInfo")', function (data) {
                    eval('data=' + data);
                    if (data.success == true) {
                        layer.alert('执行成功!', 9);
                        InitGrid();
                        HandleDialog.CloseDialog('dlg');
                    } else {
                        layer.msg(data.msg, 1);
                    }
                })
            }
        }
        //打印订单标签
        function Print() {
            var form = $('#query');
            var OrderCode = $('#txtOrderCode').val();
            var startDate = $('#checkTimeS').datebox('getValue');
            var endDate = $('#checkTimeE').datebox('getValue');
            var Status = $('#status').combobox('getValue');
            var disGs = $('#disGs').combobox('getValue');
            var disStatus = $('#disStatus').combobox('getValue');

            form.form('submit', {
                url: '@Url.Content("~/DCJDOrderInfo/ExporterExcelDetail")' + "?OrderCode=" + OrderCode + "&checkTimeS=" + startDate + "&checkTimeE=" + endDate + "&Status=" + Status + "&disGs=" + disGs + "&disStatus=" + disStatus,
                success: function (data) {
                    eval('data=' + data);
                    if (data.success) {
                        PrintContent(data.info, 0);
                    }
                    else {
                        alert(data.msg);
                    }
                }
            });
        }
        function Preview() {
            var form = $('#query');
            var OrderCode = $('#txtOrderCode').val();
            var startDate = $('#checkTimeS').datebox('getValue');
            var endDate = $('#checkTimeE').datebox('getValue');
            var Status = $('#status').combobox('getValue');
            var disGs = $('#disGs').combobox('getValue');
            var disStatus = $('#disStatus').combobox('getValue');

            form.form('submit', {
                url: '@Url.Content("~/DCJDOrderInfo/ExporterExcelDetail")' + "?OrderCode=" + OrderCode + "&checkTimeS=" + startDate + "&checkTimeE=" + endDate + "&Status=" + Status + "&disGs=" + disGs + "&disStatus=" + disStatus + "&Ispreview=1",
                success: function (data) {
                    eval('data=' + data);
                    if (data.success) {
                        PrintContent(data.info, 1);
                    }
                    else {
                        alert(data.msg);
                    }
                }
            });
        }

        function PrintCode() {
            var form = $('#query');
            var txtPrintInfo = $('#txtPrintInfo').val();
            form.form('submit', {
                url: '@Url.Content("~/DCJDOrderInfo/ExporterWOC")' + "?txtPrintInfo=" + txtPrintInfo,
                success: function (data) {
                    eval('data=' + data);
                    if (data.success) {
                        LODOP.PRINT_INIT("");
                        LODOP.ADD_PRINT_BARCODE("10mm", "5mm", "70mm", "14mm", "128Auto", txtPrintInfo);
                        if (data.info != "") {
                            LODOP.ADD_PRINT_TEXT("30mm", "5mm", "70mm", "20mm", data.info[0].GOODSNAME);
                            LODOP.SET_PRINT_STYLEA(0, "Bold", 1);
                            LODOP.SET_PRINT_STYLEA(0, "FontSize", 18);
                            var startheight = 50;
                            var arryAll = data.info;
                            if (arryAll[0].DETAILGOODSCODE != null && arryAll[0].DETAILGOODSCODE != "" && arryAll[0].SPLITFLAG == "1") {
                                LODOP.ADD_PRINT_TEXT("46mm", "5mm", "45mm", "5mm", "名称");
                                LODOP.ADD_PRINT_TEXT("46mm", "48mm", "10mm", "5mm", "数量");
                                LODOP.ADD_PRINT_TEXT("46mm", "58mm", "25mm", "5mm", "编码");
                                for (var i = 0; i < arryAll.length ; i++) {
                                    LODOP.ADD_PRINT_TEXT(startheight + "mm", "5mm", "45mm", "5mm", arryAll[i].DETAILGOODSNAME);
                                    LODOP.SET_PRINT_STYLEA(0, "FontSize", 10);
                                    LODOP.ADD_PRINT_TEXT(startheight + "mm", "49mm", "5mm", "5mm", arryAll[i].QTY);
                                    LODOP.SET_PRINT_STYLEA(0, "FontSize", 10);
                                    LODOP.ADD_PRINT_TEXT(startheight + "mm", "53mm", "25mm", "5mm", arryAll[i].DETAILGOODSCODE);
                                    LODOP.SET_PRINT_STYLEA(0, "FontSize", 10);
                                    startheight += 5;
                                }
                            }
                        }
                        LODOP.PREVIEW();
                    }
                    else {
                        alert(data.msg);
                    }
                }
            });
        }

        function deliveryEndOrder() {
            @*var orderID = "";
            var orderIDError = "";
            var rows = $('#dg').datagrid('getSelections');
            for (var i = 0; i < rows.length; i++) {
                if (rows[i].STATUS == '0') {
                    orderID = orderID + rows[i].ORDERID + ",";
                } else {
                    orderIDError = orderIDError + rows[i].ORDERID + ",";
                }

            }
            $('#hiddenOrderID').val(orderID);
            if (orderIDError != "") {
                layer.alert(orderIDError + "已下架不能推送！", 3);
            } else {
                HandleRequest.submitForm('location_Dis', '@Url.Action("SaveDataDis", "DCJDOrderInfo")', function (data) {
                    eval('data=' + data);
                    if (data.success == true) {
                        layer.alert('执行成功!', 9);
                        InitGrid();
                        HandleDialog.CloseDialog('dlg');
                    } else {
                        layer.msg(data.msg, 1);
                    }
                })
            }*@
        }

    </script>
}

<body style="background-color: ButtonFace; font-size: 17px">
    <div class="easyui-panel" title="查询条件" style="height: 130px; padding: 5px; background: #fafafa; width: 1700px;">
        <form id="query" method="post">
            <table>
                <tr>
                    <td>下单时间：
                    </td>
                    <td>
                        <input class="easyui-datebox" id="checkTimeS" name="CheckTimeS" style="width: 140px;" />
                    </td>
                    <td>~：
                    </td>
                    <td>
                        <input class="easyui-datebox" id="checkTimeE" name="CheckTimeE" style="width: 140px;" validtype="compareDate['#checkTimeS']" />
                    </td>
                    <td>订单编号:
                    </td>
                    <td>
                        <input id="txtOrderCode" name="txtOrderCode" style="width: 154px" />
                    </td>
                    <td>订单状态:
                    </td>
                    <td>
                        <select id="status" class="easyui-combobox" name="status" style="width: 154px;">
                            <option value="">--全部--</option>
                            <option value="0">未下架</option>
                            <option value="1">已下架</option>
                            <option value="2">已取消</option>
                        </select>
                    </td>
                    <td>配送公司:
                    </td>
                    <td>
                        <select id="disGs" class="easyui-combobox" name="status" style="width: 154px;">
                            <option value="">--全部--</option>
                            <option value="1">我厨</option>
                            <option value="2">达达</option>
                        </select>
                    </td>
                    <td>配送状态:
                    </td>
                    <td>
                        <select id="disStatus" class="easyui-combobox" name="status" style="width: 154px;">
                            <option value="">--全部--</option>
                            <option value="0">未配送</option>
                            <option value="1">配送中</option>
                            <option value="2">配送完成</option>
                        </select>
                    </td>
                    <td>
                        <a id="btnSerach" href="#" class="easyui-linkbutton" data-options="iconCls:'icon-search'" onclick="InitGrid()">查询</a>
                    </td>

                </tr>
                <tr>
                    <td>打印内容：</td>
                    <td>
                        <input id="txtPrintInfo" name="txtPrintInfo" style="width: 154px" />
                    </td>
                    <td>
                        <a id="btnPrint" href="#" class="easyui-linkbutton" data-options="iconCls:'icon-print'" onclick="PrintCode()">打印</a>
                    </td>
                </tr>
            </table>
        </form>

    </div>
    <div style="min-height: 720px; width: 1700px;">
        <table id="dg" title="京东订单列表" style="min-height: 600px;">
            <thead>
                <tr>
                    <th data-options="field:'ck',checkbox:true"></th>
                    <th data-options="field:'ORDERCODE',width:30">订单编号</th>
                    <th data-options="field:'RECEIVER',width:30">收货人</th>
                    <th data-options="field:'JDORDERCREATETIME',width:30,sortable:true,formatter:function(value, rowData, rowIndex){ return FormatData.formatDate(value);}">下单时间</th>
                    <th data-options="field:'SUMPRICE',width:30">商品总价</th>
                    <th data-options="field:'GOODSNUMBER',width:30">商品总数</th>
                    <th data-options="field:'ORDERSOURCE',width:30">订单来源</th>
                    <th data-options="field:'DISTRIBUTIONTYPE',width:30,sortable:true,formatter:function(value, rowData, rowIndex){ return FormatData.formatOrderDisType(value);}">配送公司</th>
                    <th data-options="field:'DISTRIBUTIONSTATUS',width:30,sortable:true,formatter:function(value, rowData, rowIndex){ return FormatData.formatOrderDisStatus(value);}">配送状态</th>
                    <th data-options="field:'RECEIVERADDRESS',width:100">收货地址</th>
                    <th data-options="field:'STATUS',width:30,sortable:true,formatter:function(value, rowData, rowIndex){ return FormatData.formatJDOrderStatus(value);}">状态</th>
                    <th data-options="field:'OPRNO',width:30">下单人</th>
                </tr>
            </thead>
        </table>
    </div>

    <div id="p2" class="easyui-dialog" style="width: 320px; height: 200px; top: 300px; left: 400px; padding: 2px"
        data-options="closed:true,buttons:'#dlg-buttons',modal:true">
        <form id="location_Dis" method="post">
            <table>
                <tr>
                    <td>配送公司:
                    </td>
                    <td>
                        <input type="hidden" id="hiddenOrderID" name="hiddenOrderID" />
                        <select id="selectDis" class="easyui-combobox" name="selectDis" style="width: 154px;">
                            <option value="1">我厨</option>
                            <option value="2">达达</option>
                        </select>
                    </td>
                </tr>
                <tr>
                    <td></td>
                    <td>
                        <a id="btnSave_batch" href="#" class="easyui-linkbutton" data-options="iconCls:'icon-save'" onclick="saveThirdDis()">确定</a>
                    </td>
                </tr>
            </table>
        </form>
    </div>
    @Html.Partial("~/Views/Shared/_PartialToolbar.cshtml", new Toolbar
{
    GridName = "dg",
    GridType = "datagrid",
    ToolbarName = "toolbar",
    FunctionModule = new Dictionary<string, List<FunctionModule>>()
    {
        {"Function",new List<FunctionModule>()
            {
              new FunctionModule(){Name = "Add",IsEnable =false },
              new FunctionModule(){Name = "Edit",IsEnable =false },
              new FunctionModule(){Name = "Remove",IsEnable =false },
              new FunctionModule(){Name = "Reload",IsEnable =true },
              new FunctionModule(){Name = "Collapse",IsEnable =false },
              new FunctionModule(){Name = "Exporter",IsEnable =false },
              new FunctionModule(){Name = "ThirdDis",IsEnable =true },
              new FunctionModule(){Name = "Preview",IsEnable =true },
              new FunctionModule(){Name = "Printer",IsEnable =true },
              new FunctionModule(){Name = "Ok",IsEnable =false },
              
            }
        }
    }
})

</body>





